// Prevents additional console window on Windows in release, DO NOT REMOVE!!
#![cfg_attr(not(debug_assertions), windows_subsystem = "windows")]

use tauri::{AppHandle, Manager,Window};
// use tauri::{SystemTray, SystemTrayMenu};
mod tray;
fn main() {
    let system_tray = tray::menu();
    tauri::Builder::default()
        .invoke_handler(tauri::generate_handler![hide_window,close_splashscreen])
        .system_tray(system_tray)
        .on_system_tray_event(|app, event| tray::handler(app, event))
        .on_window_event(|event| tray::window_handler(event))
        .run(tauri::generate_context!())
        .expect("failed to run app");
}
#[derive(Clone, serde::Serialize)]
struct Payload {
    message: String,
}

#[tauri::command]
fn hide_window(app: AppHandle) {
    println!("hide_window running");
    app.get_window("main").unwrap().hide().unwrap();
}

#[tauri::command]
async fn close_splashscreen(window: Window) {
  // 关闭启动界面
  window.get_window("splashscreen").expect("no window labeled 'splashscreen' found").close().unwrap();
  // 显示主窗口
  window.get_window("main").expect("no window labeled 'main' found").show().unwrap();
}